It is often necessary to have pointers, references and/or handles which locate and identify an object stored in memory. When the object is no longer needed, it would be preferable to be able to make the memory used to store the object available for reuse. In order for the memory to be available for reuse, it is typically necessary to insure that existing pointers, references and/or handles to the object are de-allocated, invalidated or otherwise modified so that they can no longer be used to access the memory location formerly occupied by the object. Current mechanisms available to address this memory management problem are complex, resource consuming and error-prone. One such mechanism employs a handle as described below.
A handle is a temporary name or number assigned to an object or file. For example, an operating system may assign a (typically sequential) number to each file that the operating system opens, as a way of identifying the file. A typical way to implement a handle to aid in managing objects is illustrated in FIGS. 1 and 2. FIG. 1 depicts an exemplary computing environment 10 including a computing device 5 comprising a central processing unit 22 and memory 24. Memory 24 may be any kind of volatile memory. As shown in FIG. 2, a handle 102 is associated with an index into a pointer array 104. Pointer array 104 comprises a series of entries 106, 108, 110 . . . n, to which handle 102 may point. In FIG. 2, handle 102 points to the fourth entry 112 in pointer array 104. The fourth entry 112 typically contains a pointer to an object, such as object 114. After object 114 is de-allocated, the pointer in pointer array 104 entry 112 will point to the location in memory formerly occupied by object 114 or to the location in memory occupied by a new object or to a location in memory not occupied by any object (often location zero), causing obvious problems. To prevent these problems, it is desirable to somehow locate and modify all pointers, including any copies that may exist, that point to the de-allocated object 114. This process frequently requires a significant expenditure of system resources.
There are other well-known techniques to address the memory management problem. For example, one approach is to structure the programs to prevent copying pointers, references or handles when the objects pointed to may not exist as long as the pointers, references or handles do. Minimal overhead is associated with this option but it is often not possible or not convenient to structure programs this way.
Another known technique is to keep a linked list of the pointers, references or handles and update the linked list whenever an object pointed to by an element of the linked list is de-allocated. A linked list contains at least a pointer to the next item in the list and frequently contains a pointer to the previous item in the list as well. Use of a linked list requires the use of a data structure containing an element for the storage of the pointer to the next item in the list (“next pointer”) and an element for the storage of the pointer to the previous item in the list (“previous pointer”), thus a linked list has increased space requirements. Furthermore, all code associated with the linked list must update the linked list properly, including updating the “next” and (when employed) the “previous” pointers, whenever additions or deletions to the list occur, creating added programming overhead. If multiple programs update the linked list, the linked list must be locked so that two processes do not update the list at the same time. When the object pointed to is deallocated, all the pointers, references or handles must be searched for, found and updated. Alternatively, the object could remain in memory indefinitely (until reboot) and/or be marked invalid so that subsequent access of the object is prevented. This technique would not permit the memory used to store the object to be reused and thus would require that the amount of memory available between re-boots would be adequate to store all the objects instantiated between re-boots.
Another known technique would involve keeping track of objects that are no longer in use, but not immediately making the memory location of the object available for re-use. The memory location would remain unavailable until some period of time elapsed or until some trigger condition occurred (such as available memory is running low) at which time a single search could be used to find and invalidate all the pointers, references, or handles to all those objects.
Accordingly, a primary goal of the present invention is to provide a mechanism for referencing objects that imposes minimal or no restrictions on where the references may be stored. A further goal of the present invention is to provide a mechanism that imposes little or no extra overhead when copying the object references, and that enables the object associated with the reference to be de-allocated and its memory immediately made available for reuse, without a need to search for the copies of the references or to modify the copies, and that involves little extra overhead upon object deallocation.